import QtQuick
import QtQuick.Controls
import QtQuick.Window

Window {
    signal sig_capture()
    signal sig_done(int x, int y)

    signal sig_image_update()
    signal sig_color_update(color mcolor)

    signal sig_copy_hex(string val)
    signal sig_copy_rgb(int r,int g,int b)

    property int lastWidth : 0
    property int lastHeight: 0
    property int lastX: 0
    property int lastY: 0
    property int lastFlags: 0
    property int lastVisibility: 0

    onSig_image_update: {
        //root.hide()
        root.visible = false
        root.storeWindow()

        root.visibility = Qt.WindowFullScreen
        root.flags = Qt.Window & Qt.WindowStaysOnTopHint & Qt.WindowFullScreen
        root.x = 0
        root.y = 0
        root.width = Screen.width
        root.height = Screen.height

//        img.source = ""
        img.source = "image://ScreenImage/0"
        img.visible = true

        colorPicker.enabled = true;
        //root.show()
        root.visible = true
    }
    onSig_color_update: function(mcolor){
        colorPreview.color = mcolor
        colorPreviewAlpha.text = Math.floor(mcolor.a * 255)
        colorPreviewRed.text = Math.floor(mcolor.r * 255)
        colorPreviewGreen.text = Math.floor(mcolor.g * 255)
        colorPreviewBlue.text = Math.floor(mcolor.b * 255)
        colorIndicator.color = mcolor
        val_r.value = mcolor.r * 255
        val_g.value = mcolor.g * 255
        val_b.value = mcolor.b * 255
        //temp = mcolor
        color_hex.text = mcolor
    }

    function restoreWindow() {
        root.flags = lastFlags
        root.visibility = lastVisibility
        root.x = lastX
        root.y = lastY
        root.width = lastWidth
        root.height = lastHeight
    }

    function storeWindow() {
        lastX = root.x
        lastY = root.y
        lastWidth = root.width
        lastHeight = root.height
        lastFlags = root.flags
        lastVisibility = root.visibility
    }

    id: root
    width: 800
    height: 600

    visible: true
    color: "#F0F0F0"
    title: qsTr("文件格式化")
    //anchors.margins: 10
    Rectangle {
        id: src_file
        x:6
        y:6
        width: 392//captureBtn.width
        height: 500
        //color: "#DCDCDC"
        border.color: "black"
        border.width: 1
    }

    Rectangle {
        id: dest_file
        x:402
        y:6
        width: 392//captureBtn.width
        height: 500
        //color: "#DCDCDC"
        border.color: "black"
        border.width: 1
    }
    Button {
        id: btn_open
        text: "打开文件"
        x:129
        y:531
        width: 146
        height: 55

        onClicked: {
            sig_capture();
        }
    }
    Button {
        id: btn_format
        text: "格式化"
        x:327
        y:531
        width: 146
        height: 55

        onClicked: {
            sig_capture();
        }
    }
    Button {
        id: btn_save
        text: "保存文件为"
        x:525
        y:531
        width: 146
        height: 55

        onClicked: {
            sig_capture();
        }
    }
}
